home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Technotools
/
Technotools (Chestnut CD-ROM)(1993).ISO
/
lang_oth
/
conjug
/
conjug.pro
Wrap
Text File
|
1986-05-14
|
4KB
|
128 lines
/* Conjugation program
by Neil J. Rubenking
WARNING: I am a PROLOG novice. This program is not to be
taken as an example of good programming practice. In fact,
if you see any true blunders of style, I'd appreciate your
letting me know about them!
Type in a sentence, and the program reverses the "person".
"I am the only friend you have" becomes "You are the only
friend I have". And so on. Enter a blank line to quit.
*/
nowarnings
domains
words = string*
predicates
run
Do_Line
append(words, words, words)
conjugate(string)
conj(words, words)
change(words, words)
splitup(string, words)
WriteList(words)
goal
run.
clauses
run :-
MakeWindow(1,7,112,"Conjugate",0,0,25,80),
MakeWindow(1,7,0,"",2,2,21,76),
Write("Enter single sentences -- the 'person' will be reversed."),nl,
Do_Line.
Do_Line :-
write(":>"),
ReadLn(Line),
not(conjugate(Line)), /* Conjugate ends with a "WriteList", which */
/* stops by FAILing. Hence the "not". Since */
/* a blank line succeeds with the FIRST rule */
/* in Conjugate, a blank line ends the program.*/
Do_Line.
conjugate("").
/* TO conjugate a sentence, we first split it up into a list of */
/* words. We append a marker to the beginning and end of the */
/* list, to help with capitalization. Then we call "conj" */
/* to find the conjugation of that list. Finally, we strip off */
/* the markers and print the resulting list. */
conjugate(Strin) :- splitup(Strin,List),
append(["ZXQbegin"],List,List2),
append(List2,["ZXQend"],List3),
conj(List3,NewList),
append(List4,["ZXQend"],NewList),
append(["ZXQbegin"],List5,List4),
WriteList(List5).
/* Split a string up into individual words by using "FrontToken". */
splitup(S,[H|T]) if fronttoken(S,H,S1),!,splitup(S1,T).
splitup(_,[]).
/* This "append" is slightly limited -- append(X,[],X) is true, */
/* but append([],X,X) is not. And append([],[],[]) is also false.*/
/* The order of the two clauses is important -- when we call on */
/* append to generate the possible partitions of a list (i.e., */
/* "append(L,M,[some list])", with L and M not instantiated), we */
/* want the largest L's to appear FIRST. */
append([X|L1], L2, [X|L3]) if append(L1,L2,L3).
append([X],L,[X|L]) if bound(X).
/* Y is a "conj" of X if the first part of Y is a "change" of the*/
/* first part of X, and the remainder of Y is a "conj" of the */
/* remainder of X. Note that we don't want ALL the possibilities*/
/* else we'd get "you are" -> "I am" and then also "you" -> "I". */
/* Hence the CUT after the first change succeeds. */
conj([],[]).
conj(X,Y) :-
append(Z1,R1,X),
change(Z1,Z2),!,
conj(R1,R2), /*Had to reverse these two lines*/
append(Z2,R2,Y). /* (this is the other one) */
WriteList([]).
WriteList([H|T]) :- write(H," "), WriteList(T), nl, fail.
/* Here is the database of CHANGES. Note the use of the markers */
/* "ZXQbegin" and "ZXQend". The former helps us get the capital- */
/* ization right, and the latter helps decide whether to change */
/* "you" into "I" or "me". */
change(["You","are"],["I","am"]).
change(["you","are"],["I","am"]).
change(["I","am"],["you","are"]).
change(["ZXQbegin","I","am"],["ZXQbegin","You","are"]).
change(["you","'","re"],["I'm"]).
change(["You","'","re"],["I'm"]).
change(["I","'","m"],["you're"]).
change(["ZXQbegin","I","'","m"],["ZXQbegin","you're"]).
change(["you","."],["me","."]).
change(["you","?"],["me","?"]).
change(["you","!"],["me","!"]).
change(["you","ZXQend"],["me","ZXQend"]).
change(["to","you"],["to","me"]).
change(["for","you"],["for","me"]).
change(["of","you"],["of","me"]).
change(["are","you"],["am","I"]).
change(["Are","you"],["Am","I"]).
change(["am","I"],["are","you"]).
change(["Am","I"],["Are","you"]).
change(["me"],["you"]).
change(["you"],["I"]).
change(["You"],["I"]).
change(["ZXQbegin","I"],["ZXQbegin","You"]).
change(["I"],["you"]).
change(["your"],["my"]).
change(["my"],["your"]).
change(["yours"],["mine"]).
change(["mine"],["yours"]).
change(["yourself"],["myself"]).
change(["myself"],["yourself"]).
change([X],[X]). /* The "catchall" -- X changes to X */